package com.jinghua.treatment.wechat.controller;

import com.jinghua.treatment.wechat.biz.WechatBiz;
import io.swagger.annotations.ApiOperation;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/wechat")
public class WechatController {

    @Autowired
    private WechatBiz textBiz ;

    @ApiOperation(value="微信公众平台认证")
    @RequestMapping(value="/gateway")
    @ResponseBody
    public String gateway(HttpServletRequest request,HttpServletResponse response){
        response.setCharacterEncoding("UTF-8");
        SAXReader reader = new SAXReader();
        try {
            Document document = reader.read(request.getInputStream());
            textBiz.doBussiness(document,request,response);
        } catch (DocumentException e) {
            e.printStackTrace();
            try {
                response.getWriter().write("parse xml error!");
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @ApiOperation(value="医生登录")
    @GetMapping(value="/docLogin")
    public String doctorLogin(String m,HttpServletRequest request,HttpServletResponse response){



        return "";
    }
}
